package com.controller.admin;

import com.po.Admininfo;
import com.service.admin.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;
//管理员登录控制器
@Controller
public class AdminLoginController {
    @Autowired
    private AdminService adminService;
    @RequestMapping(value = "/admin")
    public String toLogin(@ModelAttribute Admininfo admin) {
        return "admin/login";
    }
//可行的登录
//    @RequestMapping(value ="/admin/login")
//    public String login(@RequestParam String a_name,@RequestParam String a_password,Model model) {
//        System.out.println(a_name);
//        System.out.println(a_password);
//        return adminService.login(model,a_name,a_password);
//    }
      @RequestMapping(value ="/admin/login")
      public String login(@ModelAttribute Admininfo admininfo,Model model,HttpSession session) {
        System.out.println(admininfo.getA_name());
        System.out.println(admininfo.getA_password());
        return adminService.login(admininfo,model,session);
    }

    @RequestMapping(value ="admin/exit")
    public String exit(@ModelAttribute Admininfo admin,HttpSession session) {
        session.invalidate();
        return "admin/login";
    }
}